package com.demo2do.fms.admin.dao.vehicle;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.vehicle.source.Vehicle;
import com.demo2do.fms.entity.vehicle.source.VehicleGpsInfo;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface VehicleDao {

    /**
     * @param code
     * @return
     */
    @Query("FROM Vehicle WHERE disabled = false AND code = :code")
    public Vehicle loadByCode(@Variable("code") String code);
    
    /**
     * @param brandCNCode
     * @return
     */
    @Query("FROM Vehicle WHERE disabled = false AND brandCNCode = :brandCNCode")
    public Vehicle loadByBrandCNCode(@Variable("brandCNCode") String brandCNCode); 
    
    /**
     * get full_load_number by vehicle_id
     * 
     * @param vehicleId
     * @return
     */
    @Query("SELECT v.vehicleFeature.fullLoadNumber FROM Vehicle v WHERE v.id = :vehicleId")
    public Integer getFullLoadCount(@Variable("vehicleId")Long vehicleId);
    
    /**
     * 
     * @return
     */
    @Query("SELECT v.code FROM Vehicle v WHERE v.disabled = false AND NOT EXISTS (SELECT 1 FROM Driver d WHERE v.id = d.vehicleId AND d.disabled = false AND d.status = 'QUALIFIED')")
    public List<String> listNoDriverVCodes();
    
    /**
     * @param vid
     * @return
     */
    @Query("FROM VehicleGpsInfo WHERE vid = :vid")
    public VehicleGpsInfo loadVehicleGpsInfo(@Variable("vid") Long vid);
    
}
